<?php


namespace BoojasrFramework\Log;



use BoojasrFramework\Kernel;
use BoojasrMVC\AppServicesFactory;

class FileLogger extends BaseLogger
{

    protected function logImpl($content, $type)
    {
        $config = Kernel::getConfig();
        if (isset($config["logger"])&&isset($config["logger"]["path"])){
            $cachePath = $config["logger"]["path"];
            if (! is_dir($cachePath) && ! @mkdir($cachePath, 0755, true)){
                return false;
            }
            /** @var \BoojasrFramework\ServicesContainer\Kernel $kernel */
            $kernel = AppServicesFactory::$container->get("service_kernel");
            $env = $kernel->getEnv();
            $cacheFile = $cachePath."/".$env.".log";
            $tmpcontent = "";
            if (file_exists($cacheFile)){
                $tmpcontent = file_get_contents($cacheFile);
            }
            $content = $tmpcontent."[".$type."][".date("Y-m-d H:i:s")."]".$content."\n";
            return file_put_contents($cacheFile,$content);
        }
        return false;
    }

}
